import { _decorator, Component, director, Label, Node, resources, Sprite, SpriteFrame, sys } from 'cc';
import { UserInfo } from './UserInfo';
import { AudioMgr } from './AudioMgr';
import { WECHAT } from 'cc/env';
import { Adsdk } from './Adsdk';
const { ccclass, property } = _decorator;

@ccclass('Start')
export class Start extends Component {

    @property(Node)
    musicBtn:Node;

    start() {


        if(sys.platform == sys.Platform.WECHAT_GAME){
            this.node.getChildByName('sideBtn').active = false
        }else{
            this.node.getChildByName('sideBtn').active = true
        }

        if (UserInfo.isHasAudio) {
            console.log("播放")

            resources.load("IconImg/music-on/spriteFrame", SpriteFrame, (err, res) => {
                this.musicBtn.getComponent(Sprite).spriteFrame =res;
           })
            setTimeout(() => {
                AudioMgr.ins.play("audio/bgm", 1)
                    
                }, 500);
        }
        else{
            console.log("不播放")
            resources.load("IconImg/music-off/spriteFrame", SpriteFrame, (err, res) => {
                this.musicBtn.getComponent(Sprite).spriteFrame =res;
           })
           AudioMgr.ins.stop();
        }
        Adsdk.instance.hideBanner()
        Adsdk.instance.hideGridAdLeft()
        Adsdk.instance.hideGridAdRight()
        Adsdk.instance.hideGridAdTop()
        Adsdk.instance.hideGridAdRightOne()
        Adsdk.instance.hideGridAdLeftOne()
        Adsdk.instance.showBanner()
        Adsdk.instance.showGridAdLeft()
        Adsdk.instance.showGridAdRight()
        Adsdk.instance.showGridAdTop()
    }

    update(deltaTime: number) {

    }


    onclickShareBtn(){
        console.log('share')
        //@ts-ignore
        wx.shareAppMessage(function () { 
            return {
                title: '你有玩过这款超好玩的大鱼吃小鱼游戏吗?',
                imageUrl: '',
            }
        })
    }


    onclickStartGameBtn() {

        Adsdk.instance.hideBanner()
        Adsdk.instance.hideGridAdLeft()
        Adsdk.instance.hideGridAdRight()
        Adsdk.instance.hideGridAdTop()
        Adsdk.instance.hideGridAdRightOne()
        Adsdk.instance.hideGridAdLeftOne()
        Adsdk.instance.showGridAdRightOne()
        Adsdk.instance.showGridAdLeftOne()

        UserInfo.isWudiMode = false;
        AudioMgr.ins.playOneShot("audio/btn",0.7)
        director.loadScene("main")
    }

    onclickStartGame_wudi_Btn() {
        Adsdk.instance.showVideo(()=>{
            UserInfo.isWudiMode = true;
            AudioMgr.ins.playOneShot("audio/btn",0.7)
            director.loadScene("main")
        },()=>{
            console.log('广告没看完')
        })
        
    }

    onclickAudioBtn() {
        if (UserInfo.isHasAudio) {
            UserInfo.isHasAudio = false;
            AudioMgr.ins.stop();

            resources.load("IconImg/music-off/spriteFrame", SpriteFrame, (err, res) => {
                this.musicBtn.getComponent(Sprite).spriteFrame =res;
           })

            // this.audioLabel.string="声音开"
        }
        else {
            console.log("555")
            UserInfo.isHasAudio = true;
            AudioMgr.ins.play("audio/bgm", 1)

            // this.audioLabel.string="声音关"

            resources.load("IconImg/music-on/spriteFrame", SpriteFrame, (err, res) => {
                this.musicBtn.getComponent(Sprite).spriteFrame = res;
            })  

        }
    }

}


